package cn.plushine.service;

import cn.plushine.mapper.BaseWarehouseMapper;
import cn.plushine.pojo.Warehouse;
import cn.plushine.pojo.WarehouseArea;
import cn.plushine.pojo.WarehousePosition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * 仓库信息
 */
@Service
public class BaseWarehouseServiceImpl implements BaseWarehouseService {

    @Autowired
    BaseWarehouseMapper baseWarehouseMapper;

    // 获取仓库信息
    @Override
    public List<Warehouse> get() {
        return baseWarehouseMapper.get();
    }

    // 获取指定仓库区、位信息
    @Override
    public List<HashMap> getDetail(int id) {
        return baseWarehouseMapper.getDetail(id);
    }

    // 更新仓库信息
    @Override
    public int modify(Warehouse warehouse) {
        return baseWarehouseMapper.modify(warehouse);
    }

    // 删除指定仓库的所有图片
    @Override
    public int deleteImage(int id) {
        return baseWarehouseMapper.deleteImage(id);
    }

    // 添加图片
    @Override
    public int addImage(int id, List<HashMap> list) {
        return baseWarehouseMapper.addImage(id, list);
    }

    // 添加仓库信息
    @Override
    public int add(Warehouse warehouse) {
        return baseWarehouseMapper.add(warehouse);
    }

    // 获取最后一条仓库信息
    @Override
    public Warehouse getFinally() {
        return baseWarehouseMapper.getFinally();
    }

    // 删除指定仓库区信息
    @Override
    public int deleteArea(int id) {
        return baseWarehouseMapper.deleteArea(id);
    }

    // 删除指定仓库位信息
    @Override
    public int deletePosition(int id) {
        return baseWarehouseMapper.deletePosition(id);
    }

    // 添加分区
    @Override
    public int addArea(WarehouseArea warehouseArea) {
        return baseWarehouseMapper.addArea(warehouseArea);
    }

    // 查询指定仓库最新的分区id
    @Override
    public int getFinallyArea(int id) {
        return baseWarehouseMapper.getFinallyArea(id);
    }

    // 添加仓库-位信息
    @Override
    public int addPosition(WarehousePosition warehousePosition) {
        return baseWarehouseMapper.addPosition(warehousePosition);
    }

    // 更新指定仓库-区位状态
    @Override
    public int modifyAreaState(int id, boolean flag) throws Exception {
        int modifyAreaStateDB = baseWarehouseMapper.modifyAreaState(id, flag);
        if(modifyAreaStateDB!=0){
            return modifyAreaStateDB;
        }
        throw new Exception("更新指定仓库-区位状态失败！");
    }

    // 更新指定仓库-区-位状态
    @Override
    public int modifyPositionState(int id, boolean flag) throws Exception {
        int modifyPositionStateDB = baseWarehouseMapper.modifyPositionState(id, flag);
        if(modifyPositionStateDB!=0){
            return modifyPositionStateDB;
        }
        throw new Exception("更新指定仓库-区位状态失败！");
    }

}
